
export function formateMiSs(num) {
  if (isNaN(num)) return 0
  let tmpNum = parseInt(num)
  let mi = tmpNum / 60 | 0
  let ss = tmpNum % 60
  return paddingLeftZero(mi) + ':' + paddingLeftZero(ss)
}

export function paddingLeftZero(num, n = 2) {
  if (n < 1) return '00000000000'.slice(-n)
  if (isNaN(num)) return '00000000000'.slice(-n)
  let tmpStr = num + ''
  let i = 0
  while (i < n) {
    tmpStr = '0' + num
    i++
  }
  return tmpStr.slice(-n)
}

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min)
}

export function shuffle(arr) {
  let _arr = arr.slice()
  for (let i = 0; i < _arr.length; i++) {
    let j = getRandomInt(0, i)
    let t = _arr[i]
    _arr[i] = _arr[j]
    _arr[j] = t
  }
  return _arr
}
// export function shuffle2(parr) {
//   let arr = parr.slice()
//   let i = arr.length
//   while (i) {
//     let j = Math.floor(Math.random() * i--)
//     [arr[j], arr[i]] = [arr[i], arr[j]]
//   }
//   return arr
// }

export function debounce(fn, delay) {
  let timer = null

  return function(...args) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  }
}
